<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
                <!--<legend>搜索信息</legend>-->
                <div style="margin: 10px 10px 10px 10px">

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <!--<label class="layui-form-label">团队名称</label>-->
                            <div class="layui-input-inline">
                                <input type="text" name="search" autocomplete="off"  placeholder="按【团队名称】【手机号】搜索" class="layui-input soso">
                            </div>
                        </div>
                     <!--   <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" maxlength="11" name="phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>-->
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>

                </div>
        </form>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="ldelete">查看团队</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        </script>

    </div>
</div>
{include file="public/footer" /}
<!--<script type="text/html" id="look">
    <button data-method="offset" data-type="auto" class="layui-btn " id="lookstyle" lay-event="look">查看</button>
</script>-->
<script type="text/html" id="matchingType">
    {{#  if(d.matching_type === 1){ }}
    <!--<span style="color: #28f51d;">账号正常</span>-->
    <span> 独立匹配</span>
    {{#  } else { }}

    <span>综合匹配</span>
    {{#  } }}
</script>
<script>
    var hideMark = true;
    if ("{$mark}" != '') {
        hideMark = false;
    }
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/team/index?active=ajax',
            method: 'post',
            where: {mark: "{$mark}"},
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            // defaultToolbar: '',
            cols: [[
                // {type: "checkbox",},
                {title: '排名', type: 'numbers', width: 100, hide: hideMark},
                {field: 'title', title: '团队名称'},
                {
                    field: 'member_cod', title: '团队领导', sort: false, align: 'center', event: 'look', style: 'cursor: pointer;',
                    templet: function (d) {
                        return '<a href="#" style="color: #1e9fff;text-decoration: underline;">' + d.name + '</a>';
                    }
                },
                {field: 'create_time', title: '创建日期'},
                {field: 'team_num', title: '团队人数', sort: true},
                {field: 'team_earnings', title: '团队总收益', sort: true},
                {field: 'matching_type', title: '匹配类型', templet: '#matchingType'},
                {title: '操作', toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'

        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {
                //默认prompt
                layer.prompt({
                    formType: 0,
                    phone: '',
                    title: '请输入手机号'
                },function(phone, index){
                    if (isNaN(phone)) {
                        layer.msg("请输入手机号!",{ icon:5,
                            time: 1000});
                        return;
                    } else {
                        $.ajax({
                            url: '/admin/team/member_so',
                            type: 'post',
                            dataType: 'json',
                            data: {phone:phone},
                            success: function (res) {
                                if (res.status == true) {    // 获得frame索引
                                    var index = layer.open({
                                        title:'玩家信息',
                                        type: 2,
                                        area: ['100%', '100%'],
                                        fixed: false, //不固定
                                        shade:0.5,
                                        shadeClose:true,
                                        content: "/admin/team/getMember?type=teamCreate&phone="+phone,
                                    });
                                }else{
                                    layer.msg(res.msg,{ icon:5,
                                        time: 1000});
                                }
                            },
                            error: function () {
                                layer.msg("报错了");
                            }
                        });

                    }


                    return false;
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            } else if (obj.event === 'LAYTABLE_TIPS') {
                alert('自定义的,不用的话可以将该方法删除')
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var id = obj.data.id;
            var memberCode = obj.data.member_code;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/admin/team/write?id=" + id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'look') {
                //触发事件  查看内容
                var index = layer.open({
                    title: '领导人信息',
                    type: 2,
                    area: ['100%', '100%'],
                    fixed: false, //不固定
                    shade: 0.5,
                    shadeClose: true,
                    content: '/admin/member/write?code='+ memberCode,
                });
            } else if (obj.event === 'ldelete') {
                //触发事件  查看这个团队的所有玩家
                var index = layer.open({
                    title: '我的团队',
                    type: 2,
                    area: ['100%', '100%'],
                    fixed: false, //不固定
                    shade: 0.5,
                    shadeClose: true,
                    content: '/admin/member/index?mark=team&teamId=' + id,
                });
            }
        });


    });
</script>

</body>
</html>